class AnimationManager {
	private animations: Array<() => void> = []
	private running: boolean = false
	private animationId: number = 0

	/**
	 * @description 添加动画
	 * @param animation
	 */
	addAnimation(animation: () => void) {
		this.animations.push(animation)
	}

	start() {
		this.running = true
		this.animate()
	}

	stop() {
		this.running = false
		cancelAnimationFrame(this.animationId)
	}

	status() {
		return this.running ? 'runing' : 'stop'
	}

	private animate() {
		this.animationId = requestAnimationFrame(this.animate.bind(this))
		this.animations.forEach((animation) => animation())
	}
}

export default AnimationManager
